package com.qs.config.esconfig;

/**
 * ClassName: RestClientConfig
 * Package: com.qs.config.esconfig
 * Description:
 *
 * @Author: @weixueshi
 * @Create: 2023/12/28 - 22:59
 * @Version: v1.0
 */

import lombok.Data;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;

/**
 * ElasticSearch 客户端配置
 */
@Data
@Configuration
@ConfigurationProperties("spring.elasticsearch")
public class RestClientConfig extends AbstractElasticsearchConfiguration {

    private String uris;

    @Bean
    @Override
    public RestHighLevelClient elasticsearchClient() {
        final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo(uris)
                .build();
        return RestClients.create(clientConfiguration).rest();
    }
}
